﻿#pragma once

#include "Client.h"
#include "Protocol.h"
#include "sqlite3.h"

typedef CMap<CString, LPCTSTR, Client*, Client*> OnlineUsers;

// 服务器
class Server: public CSocket {
    friend class Client;

    private: sqlite3* mDatabase;        // 数据库
    private: OnlineUsers mOnlineUsers;  // 在线用户列表

    public: Server();
    public: ~Server();
    private: void CreateDatabase();
    private: void HandleAddFriendRequest(AddFriendRequest*, Client*);
    private: void HandleAddFriendResult(AddFriendResult*);
    private: void HandleChat(ChatInfo*);
    private: void HandleLogoff(LogoffRequest*);
    private: void HandleLogon(LogonRequest*, Client*);
    private: void HandleReg(RegRequest*, Client*);
    private: virtual void OnAccept(int);
    public: void OnGetMessageFromClient(ImProtocol*, Client*);
    private: void SendData(Client*, ImProtocol*, int);
    public: BOOL Start();
};
